<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>商家管理</title>
    <!-- 引入Bootstrap CSS -->
    <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.css">
    <!-- 引入jQuery -->
    <script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.1.1/jquery.min.js"></script>
    <script src="./bootstrap/js/bootstrap.js"></script>
</head>
<script>
    window.onload = function () {
        // 获取所有的商家信息
        $.ajax({
            url: 'merchant/all',
            type: 'GET',
            dataType: 'json',
            success: function (res) {
                console.log('====>>>>',res.data)
                if (res.code == 200) {

                    let data_val = res.data
                    console.log('111', data_val)
                    for (var i = 0; i < data_val.length; i++) {
                        console.log('====>>>>', data_val[i].mname)
                        // 拼接字符串
                        let status_val = data_val[i].mstatus;
                        if (status_val == 0) {
                            status_val = '待审核';
                        } else if (status_val == 1) {
                            status_val = '已通过';
                        } else {
                            status_val = '未通过';
                        }
                        $("<tr><td>"+(data_val[i].mid)+"</td>" +
                            "<td>"+data_val[i].mrealName+"</td>" +
                            "<td>"+data_val[i].mcontact+"</td>" +
                            "<td>"+data_val[i].mphone+"</td>" +
                            "<td>"+data_val[i].memail+"</td>" +
                            "<td>"+data_val[i].maddress+"</td>" +
                            "<td>"+ (data_val[i].merchantType == 1 ? '个人' : '企业') +"</td>" +
                            "<td>"+data_val[i].midCard+"</td>" +
                            "<td>"+status_val+"</td>" +
                            "<td>"+data_val[i].create_time+"</td>" +
                            "<td><button class='btn btn-success btn-sm' onclick='checkResu("+data_val[i].mid+")'>通过</button>" +
                            "&nbsp;&nbsp;<button onclick='uncheck("+data_val[i].mid+")' class='btn btn-danger btn-sm'>拒绝</button>" +
                            "</td></tr>").appendTo($("#tb"));
                    }
                }
            },
            complete: function (res) {
                console.log(res);
            }
        });
    }
    // 平台审核商家
    function checkResu(obj) {
        // alert('审核'+obj)
        let anw = window.confirm("你确定要对【"+obj+"】这条数据进行审核吗？");
        if (anw) {
            $.ajax({
                url: 'merchant/status/' + obj,
                type: 'get',
                dataType: 'json',
                success: function (res) {
                    console.log('====>>>>',res)
                    if (res.code == 200) {
                        alert('审核成功')
                        window.location.reload()
                    } else {
                        alert(res.message)
                    }
                }
            })
        } else {
            return;
        }
    }
    // 拒绝通过
    function uncheck(obj) {
        // alert("资料不合适，拒绝通过")
        let anw = window.confirm("你确定要对【"+obj+"】这条数据置为不通过状态吗？");
        if (anw) { // 如果点击的是确定（确定拒绝）
            $.ajax({
                url: 'merchant/unstatus/'+obj,
                type: 'get',
                dataType: 'json',
                success: function (res) {
                    console.log('====>>>>',res)
                    if (res.code == 200) {
                        alert('已拒绝该商家的入驻申请')
                        window.location.reload()
                    } else {
                        alert(res.message)
                    }
                }
            })
        } else {
            return;
        }
    }


    function queryByCondtion(obj) {
        // console.log(obj)
        $.ajax({
            url: 'merchant/queryByCondtion?mrealName='+obj,
            type: 'get',
            dataType: 'json',
            success: function (res) {
                console.log('》》》》》》====>>>>',res)
                if (res.code == 200) {
                    // 清空上一次的记录
                    $("#tb").empty();
                    let data_val = res.data
                    console.log('111', data_val)
                    for (var i = 0; i < data_val.length; i++) {
                        console.log('====>>>>', data_val[i].mname)
                        // 拼接字符串
                        let status_val = data_val[i].mstatus;
                        if (status_val == 0) {
                            status_val = '待审核';
                        } else if (status_val == 1) {
                            status_val = '已通过';
                        } else {
                            status_val = '未通过';
                        }
                        $("<tr><td>"+(data_val[i].mid)+"</td>" +
                            "<td>"+data_val[i].mrealName+"</td>" +
                            "<td>"+data_val[i].mcontact+"</td>" +
                            "<td>"+data_val[i].mphone+"</td>" +
                            "<td>"+data_val[i].memail+"</td>" +
                            "<td>"+data_val[i].maddress+"</td>" +
                            "<td>"+ (data_val[i].merchantType == 1 ? '个人' : '企业') +"</td>" +
                            "<td>"+data_val[i].midCard+"</td>" +
                            "<td>"+status_val+"</td>" +
                            "<td>"+data_val[i].create_time+"</td>" +
                            "<td><button class='btn btn-success btn-sm' onclick='checkResu("+data_val[i].mid+")'>通过</button>" +
                            "&nbsp;&nbsp;<button onclick='uncheck("+data_val[i].mid+")' class='btn btn-danger btn-sm'>拒绝</button>" +
                            "</td></tr>").appendTo($("#tb"));
                    }
                }
            }
        });
    }
</script>
<body>
<!--
<form class="form-horizontal">
    <div class="form-group">
        <label for="inputmcontact" class="col-sm-2 control-label">商家联系人</label>
        <div class="col-sm-8">
            <input type="email" class="form-control" id="inputmcontact" placeholder="请输入商家联系人">
        </div>
    </div>
    <div class="form-group">
        <label for="inputmphone" class="col-sm-2 control-label">商家联系方式</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="inputmphone" placeholder="请输入商家联系方式">
        </div>
    </div>
    <div class="form-group">
        <label for="inputmemail" class="col-sm-2 control-label">商家联系邮箱</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="inputmemail" placeholder="请输入商家联系邮箱">
        </div>
    </div>
    <div class="form-group">
        <label for="inputmaddress" class="col-sm-2 control-label">商家联系地址</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="inputmaddress" placeholder="请输入商家联系地址">
        </div>
    </div>
    <div class="form-group">
        <label for="inputmerchantType" class="col-sm-2 control-label">商家类型</label>
        <div class="col-sm-8">
           <select id="inputmerchantType" class="form-control">
               <option value="1">个人</option>
               <option value="2">企业</option>
           </select>
        </div>
    </div>
    <div class="form-group">
        <label for="inputmrealName" class="col-sm-2 control-label">商家真实名称</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="inputmrealName" placeholder="请输入商家真实名称 ">
        </div>
    </div>
    <div class="form-group">
        <label for="inputmidCare" class="col-sm-2 control-label">商家证件号</label>
        <div class="col-sm-8">
            <input type="text" class="form-control" id="inputmidCare" placeholder="请输入商家证件号">
        </div>
    </div>
    <div class="form-group">
        <label for="file" class="col-sm-2 control-label">商家证件图</label>
        <div class="col-sm-8">
            <input type="file" class="form-control" id="file">
        </div>
    </div>

</form>
<div class="form-group">
    <div class="col-sm-offset-2 col-sm-8">
        <button type="button" class="btn btn-success">提交</button>
    </div>
</div>
-->

<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">

            <a class="navbar-brand" href="#">Brand</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <form class="navbar-form navbar-left">
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search">
                </div>
                <button type="submit" class="btn btn-default">Submit</button>
            </form>

        </div><!-- /.navbar-collapse -->
    </div><!-- /.container-fluid -->
</nav>

<table class="table table-striped table-hover">
    <thead>
        <th>#</th>
        <th>商家联系人</th>
        <th>商家联系方式</th>
        <th>商家联系邮箱</th>
        <th>商家联系地址</th>
        <th>商家类型</th>
        <th>商家真实名称</th>
        <th>商家证件号</th>
        <th>商家证件图</th>
        <th>操作</th>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>
                <button class="btn btn-success">通过</button>
                <button class="btn btn-danger">拒绝</button>
            </td>
        </tr>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>
                <button class="btn btn-success">通过</button>
                <button class="btn btn-danger">拒绝</button>
            </td>
        </tr>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>
                <button class="btn btn-success">通过</button>
                <button class="btn btn-danger">拒绝</button>
            </td>
        </tr>
        <tr>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>1</td>
            <td>
                <button class="btn btn-success">通过</button>
                <button class="btn btn-danger">拒绝</button>
            </td>
        </tr>


    </tbody>
    <tfoot>
    <tr>
        <td colspan="10">
        123456
        </td>
    </tr>
    </tfoot>
</table>

<form class="navbar-form navbar-left">
    <div class="form-group">
        <input type="text" class="form-control" placeholder="请输入关键字查询" oninput="queryByCondtion(this.value)">
    </div>
</form>

</body>
</html>